//// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
//package com.linqingying.gitcode.pullrequest
//
//import com.intellij.openapi.components.service
//import com.intellij.openapi.project.Project
//import com.intellij.openapi.vfs.VirtualFile
//import com.intellij.openapi.vfs.VirtualFileManager
//import com.intellij.vcs.editor.ComplexPathVirtualFileSystem
//import com.intellij.vcs.editor.GsonComplexPathSerializer
//import com.linqingying.gitcode.api.GCRepositoryCoordinates
//import com.linqingying.gitcode.pullrequest.data.GCPRDataContextRepository
//import com.linqingying.gitcode.pullrequest.data.GCPRIdentifier
//
//internal class GCPRVirtualFileSystem : ComplexPathVirtualFileSystem<GCPRVirtualFileSystem.GCPRFilePath>(
//  GsonComplexPathSerializer(GCPRFilePath::class.java)
//) {
//  override fun getProtocol() = PROTOCOL
//
//  override fun findOrCreateFile(project: Project, path: GCPRFilePath): VirtualFile? {
//    val filesManager = GCPRDataContextRepository.getInstance(project).findContext(path.repository)?.filesManager ?: return null
//    val pullRequest = path.prId
//    return when {
//      pullRequest != null -> if(path.isDiff) filesManager.findDiffFile(pullRequest) else filesManager.findTimelineFile(pullRequest)
//      path.isDiff -> filesManager.createOrGetNewPRDiffFile()
//      else -> null
//    }
//  }
//
//  fun getPath(fileManagerId: String,
//              project: Project,
//              repository: GCRepositoryCoordinates,
//              id: GCPRIdentifier?,
//              isDiff: Boolean = false): String =
//    getPath(GCPRFilePath(fileManagerId, project.locationHash, repository, id, isDiff))
//
//  data class GCPRFilePath(override val sessionId: String,
//                          override val projectHash: String,
//                          val repository: GCRepositoryCoordinates,
//                          val prId: GCPRIdentifier?,
//                          val isDiff: Boolean) : ComplexPath
//
//  companion object {
//    private const val PROTOCOL = "ghpr"
//
//    fun getInstance() = service<VirtualFileManager>().getFileSystem(PROTOCOL) as GCPRVirtualFileSystem
//  }
//}
